<template>
	<view>
		<view class="top">
			<!-- <image src="../../../static/img/banner.png" mode=""></image> -->
			<image v-show="imageObj.imgLoaded" :src="getImagUlr(imageObj.logo)" mode="" @error="onErrorImg(imageObj)" @load="onSuccessImg(imageObj)"></image>
			<image v-show="!imageObj.imgLoaded" src="/static/images/load_fial_image.png" />
			
		</view>
		<view class="mid">
			<view class="mid-top">
				<view class="mid-top-top">
					<view class="money">￥{{productList.pricePerMonth}}/月</view>
					<text>主机</text>
				</view>
				<text>{{productList.description}}</text>
			</view>
		</view>
		<view class="section">
			<view class="section1">
				<text class="word">产品名称</text>
				<text class="name">{{productList.productName}}</text>
			</view>
			<view class="section1">
				<text class="word">所属网络</text>
				<text class="name">{{productList.netName}}</text>
			</view>

		</view>
		<view class="section2">
			<text class="word">包含频道</text>
			<view class="include">
				<view v-for="(item,index) in productList.serviceIncluded" :key="index">
					<text class="title">{{item.serviceName}}</text>
				</view>
			</view>
		</view>
		<!-- <view class="bottom">
			<view class="bottom-left">
				加入购物车
			</view>
			<view class="bottom-right" @tap="ensure">
				立即购买
			</view>
		</view> -->
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex' //导入vuex的mapState和mapMutations方法
	import apis from '../../../api.js'
	export default {
		data() {
			return {
				productId: '',
				productList: [],
				productImages:[],
				imageObj:{
					imgLoaded:false,
					logo:'/static/images/load_fial_image.png'
				},
			}
		},
		computed: {
			...mapState(['userInfo']), //对全局变量进行监控
		},
		onLoad() {
			apis.Productlist({
				"nitId": this.userInfo.netId,
				"userlevel": this.userInfo.userLevel
			}).then(res => {
				//console.log(res)
				this.productList = res[1].data.content[1]
				this.productId = res[1].data.content[1].productId
			})
		},
		methods: {
			onSuccessImg(item) {
				this.$set(item, 'imgLoaded', true)
			},
			onErrorImg(item) {
				this.$set(item, 'imgLoaded', false)
			},
			getImagUlr(icon){
				console.log('套餐图片下载')
				var self = this;
				var tempImagePath = uni.getStorageSync('tempImagePath');
				if (tempImagePath && tempImagePath[icon]) {					
					self.productImages[icon] = tempImagePath[icon];				     
				} 
				else {
					let options = {
						url:httpRequest.requestUrl.imageUrl + icon						
					};
					
					httpRequest.DownloadFile(options).then(res => {						
						if(res.statusCode == 200){							
							var tempImagePath = uni.getStorageSync('tempImagePath');
							if (tempImagePath && tempImagePath[icon]) {								
								self.productImages[icon] = tempImagePath[icon];				     
							}
							else{								
								self.productImages[icon] = '/static/images/load_fial_image.png'; 
							} 
						}
						else{
							self.productImages[icon] = '/static/images/load_fial_image.png'; 
						}
					})
					self.productImages[icon] = '/static/images/load_fial_image.png'; 
				}
				
				return self.productImages[icon];
			}
			// ensure() {
			// 	let that = this
			// 	that.productId = this.productId
			// 	uni.navigateTo({
			// 		url: '../ensureorder/ensureorder?type=' + that.type
			// 	})
			// }
		}
	}
</script>

<style scoped>
	.top {
		width: 100%;
		height: 320rpx;
	}

	.top image {
		width: 100%;
		height: 320rpx;
	}

	.mid {
		width: 100%;
		display: flex;
		flex-direction: column;
	}

	.mid-top {
		width: 100%;
		height: 140rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: space-around;
	}

	.mid-top>text {
		width: 90%;
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: 400;
		color: #161616;
	}

	.mid-top-top {
		width: 90%;
		display: flex;
		align-items: center;
	}

	.mid-top-top>text {
		width: 86rpx;
		height: 48rpx;
		opacity: 1;
		border-radius: 4rpx;
		text-align: center;
		line-height: 48rpx;
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: 400;
		color: #FFFFFF;
		background-color: #00B9EF;
	}

	.money {
		width: 220rpx;
		height: 56rpx;
		font-size: 40rpx;
		font-family: PingFang SC;
		font-weight: 400;
		line-height: 56rpx;
		color: #FF1F1F;
		opacity: 1;
	}

	.mid-bottom {
		width: 100%;
		height: 132rpx;
		display: flex;
		align-items: center;
		background: #F1F1F1;
	}

	.mid-bottom-content {
		width: 100%;
		height: 88rpx;
		background: #FFFFFF;
		display: flex;
		justify-content: space-around;
		align-items: center;
	}

	.mid-bottom-content>text {
		width: 86rpx;
		height: 48rpx;
		border: 2rpx solid #FF0000;
		opacity: 1;
		text-align: center;
		line-height: 48rpx;
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: 400;
		color: #FF0000;
	}

	.content-blue {
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: 400;
		color: #00B9EF;
		opacity: 1;
	}

	.content-red {
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: 400;
		color: #FF0000;
		opacity: 1;
	}

	.section {
		width: 100%;
		display: flex;
		flex-direction: column;
	}

	.section1 {
		width: 100%;
		height: 80rpx;
		display: flex;
		align-items: center;
		border-bottom: 1rpx solid #e5e5e5;
	}

	.word {
		width: 30%;
		height: 80rpx;
		text-align: center;
		line-height: 80rpx;
		color: #A9A9A9;
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: 400;
	}

	.name {
		width: 70%;
		height: 80rpx;
		line-height: 80rpx;
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: 400;
		color: #030303;
	}

	.section2 {
		width: 100%;
		display: flex;
		flex-direction: column;
		margin-bottom: 100rpx;
	}

	.include {
		width: 100%;
		display: flex;
		flex-wrap: nowrap;
		/*换行，第一行在上方*/
		flex-wrap: wrap;
		/*换行，第一行在下方*/
		/* flex-wrap: wrap-reverse; */
	}

	.title {
		width: 300rpx;
		height: 68rpx;
		background: #F3F3F3;
		opacity: 1;
		border-radius: 68rpx;
		font-size: 15px;
		font-family: PingFang SC;
		font-weight: 400;
		color: #00B9EF;
		display: flex;
		justify-content: center;
		align-items: center;
		margin-left: 50rpx;
		margin-top: 20rpx;
	}

	.bottom {
		width: 100%;
		height: 100rpx;
		position: fixed;
		bottom: 0;
		z-index: 1010;
		display: flex;
	}

	.bottom-left {
		width: 50%;
		height: 100rpx;
		line-height: 100rpx;
		text-align: center;
		background-color: #FFFFFF;
		color: #000000;
		font-size: 34rpx;
	}

	.bottom-right {
		width: 50%;
		height: 100rpx;
		line-height: 100rpx;
		text-align: center;
		background-color: #FF0000;
		font-size: 34rpx;
		color: #FFFFFF;
	}
</style>
